package com.itheima.tanhua.vo;

import cn.hutool.core.util.ArrayUtil;
import com.itheima.tanhua.domain.Analysis;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Lff
 * @date 2022/4/10
 * <p>
 * 前端信息展示。
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DashboardVo {
    private String title;//日期
    private Integer amount;//数量

    /**
     * 初始化汇总
     * DashboardVo dashboardVo = new DashboardVo();
     * dashboardVo.setTitle(new SimpleDateFormat("yyyy-MM-dd").format(analysis.getRecordDate()));
     * if (type.equals("101")) {
     * dashboardVo.setAmount(analysis.getNumRegistered());
     * } else if (type.equals("102")) {
     * dashboardVo.setAmount(analysis.getNumActive());
     * } else if (type.equals("103")) {
     * <p>
     * }
     *
     * @param thisYear
     * @param type
     * @return
     */
    public static DashboardVo[] init(List<Analysis> thisYear, String type) {
        List<DashboardVo> dashboardVos = new ArrayList<>();
        for (Analysis analysis : thisYear) {
            DashboardVo dashboardVo = new DashboardVo();
            dashboardVo.setTitle(new SimpleDateFormat("yyyy-MM-dd").format(analysis.getRecordDate()));
            if (type.equals("101")) {
                dashboardVo.setAmount(analysis.getNumRegistered());
            } else if (type.equals("102")) {
                dashboardVo.setAmount(analysis.getNumActive());
            } else if (type.equals("103")) {
                dashboardVo.setAmount(analysis.getNumRetention1d());
            }
            dashboardVos.add(dashboardVo);
        }
        return ArrayUtil.toArray(dashboardVos, DashboardVo.class);
    }
}
